package ink.tiptop.utils.date;

import java.sql.Timestamp;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.ZoneId;
import java.util.Date;

public class LocalDateTimeHolder {

    private LocalDateTime localDateTime;

    public LocalDateTimeHolder(LocalDateTime localDateTime) {
        this.localDateTime = localDateTime;
    }

    /**
     * 转换成指定格式的时间字符串输出
     *
     * @param pattern
     * @return
     */
    public String toString(DateBaseHolder.Pattern pattern) {
        return localDateTime.format(DateBaseHolder.getFormatter(pattern));
    }

    /**
     * 转换成Date
     *
     * @return
     */
    public Date toDate() {
        return Date.from(localDateTime.atZone(ZoneId.systemDefault()).toInstant());
    }

    /**
     * 转换成Long类型
     *
     * @return
     */
    public Long toLong() {
        return localDateTime.atZone(ZoneId.systemDefault()).toInstant().toEpochMilli();
    }

    /**
     * 转换成TimeStamp类型
     *
     * @return
     */
    public Timestamp toTimeStamp() {
        return new Timestamp(localDateTime.atZone(ZoneId.systemDefault()).toInstant().toEpochMilli());
    }


    /**
     * 某天最小值(零点)
     *
     * @return
     */
    public LocalDateTimeHolder min() {
        this.localDateTime = LocalDateTime.of(localDateTime.toLocalDate(), LocalTime.MIN);
        return this;
    }

    /**
     * 某天最大值(结束点)
     *
     * @return
     */
    public LocalDateTimeHolder max() {
        this.localDateTime = LocalDateTime.of(localDateTime.toLocalDate(), LocalTime.MAX);
        return this;
    }

}
